package fx.game.demo.event;

import fx.game.demo.common.LayoutManage;
import fx.game.demo.common.WindowManage;
import javafx.event.EventHandler;
import javafx.scene.input.KeyEvent;

/**
 *
 * @author: datom
 *
 * @create: 2021/12/2 19:20
 *
 * @Deprecated 游戏事件
 *
 **/
public class GameEvent{

    private static EventHandler<KeyEvent> operatingGameKeyboardEvents;


    /**
     * @Author: datom
     * @Date: 2021/12/6 18:26
     *
     * @Description: 获取操作游戏事件
     *
     */
    public static EventHandler<KeyEvent> getOperatingGameKeyboardEvents() {
        if(operatingGameKeyboardEvents == null) {
            operatingGameKeyboardEvents = new EventHandler<KeyEvent>() {
                @Override
                public void handle(KeyEvent event) {
                    //阻止其他元素接收到该事件
                    event.consume();
                    System.out.println(event.getCode().getName());

                    if(event.getCode().getName().equals("Left")) {
                        LayoutManage.getGameLayout().updateAllNumber(1);

                    }else if(event.getCode().getName().equals("Up")) {
                        LayoutManage.getGameLayout().updateAllNumber(2);

                    }else if(event.getCode().getName().equals("Right")) {
                        LayoutManage.getGameLayout().updateAllNumber(3);

                    }else if(event.getCode().getName().equals("Down")) {
                        LayoutManage.getGameLayout().updateAllNumber(4);
                    }
                }
            };
        }
        return operatingGameKeyboardEvents;
    }

    /**
     * @Author: datom
     * @Date: 2021/12/6 18:36
     *
     * @Description: 游戏失败事件
     *
     */
    public static void gameOver() {
        System.out.println("Game Over !");
        WindowManage.getGameOverTips().show();
    }

}
